package mysql

import (
	"data-transfer/domain"
	"data-transfer/global"
	"data-transfer/transfer"
	"encoding/json"
	"github.com/shopspring/decimal"
	"go.uber.org/zap"
	"golang.org/x/net/context"
)

//GetAppendedBizData 取得指定时间间隔的业务数据
func (mdb *db) GetAppendedBizData(ctx context.Context, tableName string, startDate string, endDate string) (interface{}, error) {

	// 查询指定录入日期范围的业务数据
	/*
		sql := "select * from"+tableName+"  where UNIX_TIMESTAMP(ENTRYDATE) between UNIX_TIMESTAMP('" + startDate + "') and UNIX_TIMESTAMP('" + endDate + "') "
		datas, err := mdb.db.Query(sql)
		if err != nil {
			global.LOG.Error("查询【"+tableName+"】信息出错:", zap.Any("err", err))
			return nil, err
		}

	*/
	if len(startDate) == 0 || len(endDate) == 0 {
		global.LOG.Error("没有正确输入需要导入数据的起始日期和结束日期！")
		return nil, nil
	}
	switch tableName {
	case "TQ_FIN_PRGBALSHEETNEW": // 一般企业资产负债表(新准则产品表)

		var results []*domain.BALANCE_SHEET
		var rows []*domain.TQ_FIN_PRGBALSHEETNEW
		err := mdb.db.NewSession().Where("ISVALID=? and REPORTTYPE = ? and ENTRYDATE between ?  and  ?", 1, transfer.REPORTTYPE_1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的资产负债数据出错:", zap.Any("err", err))
			return nil, err
		}
		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, v := range rows {
			r := new(domain.BALANCE_SHEET)
			compCode := v.Compcode
			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {
				r.Symbol = basicInfo.Symbol
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Compcode = v.Compcode                                   //机构代码
				r.Reportyear = v.Reportyear                               //会计年度
				r.Reportdatetype = v.Reportdatetype                       //报告期类型

				r.Totcurrasset = v.Totcurrasset       //流动资产
				r.Curfds = v.Curfds                   //货币资金
				r.Tradfinasset = v.Tradfinasset       //交易性金融资产
				r.Inve = v.Inve                       //存货
				r.Accorece = v.Accorece               //应收账款
				r.Otherrecetot = v.Otherrecetot       //其他应收款
				r.Totalnoncassets = v.Totalnoncassets //非流动资产合计
				r.Fixedassenet = v.Fixedassenet       //固定资产净额
				r.Avaisellasse = v.Avaisellasse       //可供出售金融资产
				r.Intaasset = v.Intaasset             //无形资产
				r.Goodwill = v.Goodwill               //商誉
				r.Totasset = v.Totasset               //总资产
				r.Totalcurrliab = v.Totalcurrliab     //流动负债合计
				r.Advapaym = v.Advapaym               //预收账款
				r.Accopaya = v.Accopaya               //应付账款
				r.Totalnoncliab = v.Totalnoncliab     //长期负债
				r.Totliab = v.Totliab                 //总负债
				r.Paresharrigh = v.Paresharrigh       //股东权益
				r.Capisurp = v.Capisurp               //资产公积金
				r.Shorttermborr = v.Shorttermborr     //短期借款

				results = append(results, r)
			}
		}
		return results, nil
	case "TQ_FIN_PRGINCSTATEMENTNEW": //一般企业利润表(新准则产品表)

		var results []*domain.INCOME_STATEMENT
		var rows []*domain.TQ_FIN_PRGINCSTATEMENTNEW
		err := mdb.db.NewSession().Where("ISVALID=? and REPORTTYPE = ? and ENTRYDATE between ?  and  ?", 1, transfer.REPORTTYPE_1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的企业利润数据出错:", zap.Any("err", err))
			return nil, err
		}

		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, v := range rows {
			compCode := v.Compcode

			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {

				isBank := false
				//根据compCode判断企业性质
				compInfos, _ := mdb.GetTqCompInfoByCompCode(ctx, compCode)
				if len(compInfos) > 0 {
					compInfo := compInfos[0]
					if compInfo.Comptype1 == transfer.TQCOMPINFO_BDFI || compInfo.Comptype1 == transfer.TQCOMPINFO_BNDFI { //银行
						isBank = true
					}
				}

				r := new(domain.INCOME_STATEMENT)
				r.Symbol = basicInfo.Symbol
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Reportyear = v.Reportyear                               //会计年度
				r.Reportdatetype = v.Reportdatetype                       //报告期类型
				r.Compcode = v.Compcode                                   //机构代码
				r.Biztotinco = v.Bizinco                                  // 营业收入
				r.Biztotcost = v.Bizcost                                  //营业成本

				//如果是银行，查询银行利润表，取得相应日期和类型的数据
				if isBank {
					binc, eb := mdb.GetTqFinPrgbincstatementnewByBizKey(ctx, compCode, v.Enddate, v.Reportyear, v.Reportdatetype)
					if eb != nil {
						global.LOG.Error("获取 银行利润表(新准则产品表) 数据出错", zap.Any("err", eb))
					}
					if binc != nil {
						//银行 三费合一  业务及管理费用
						expen := binc.Bizadminexpen
						r.Manaexpe = expen  //管理费用
						r.Salesexpe = expen //营业费用
						r.Finexpe = expen   //财务费用
					}
				} else {
					r.Manaexpe = v.Manaexpe   //管理费用
					r.Salesexpe = v.Salesexpe //营业费用
					r.Finexpe = v.Finexpe     //财务费用
				}

				r.Perprofit = v.Perprofit //营业利润
				r.Inveinco = v.Inveinco   // 投资收益
				r.Nonoreve = v.Nonoreve   //营业外收入净额
				r.Nonoexpe = v.Nonoexpe   //营业外支出净额
				//设置营业外收支净额
				nonoreveDec, _ := decimal.NewFromString(v.Nonoreve)
				nonoexpeDec, _ := decimal.NewFromString(v.Nonoexpe)
				nnoiDec := nonoreveDec.Sub(nonoexpeDec)
				r.Nonoreve = nnoiDec.String() //营业外收支净额

				r.Totprofit = v.Totprofit //利润总额
				r.Netprofit = v.Netprofit //净利润

				results = append(results, r)

			}
		}
		return results, nil
	case "TQ_FIN_PRGCFSTATEMENTNEW": // 现金流量
		var results []*domain.CASH_FLOW
		var rows []*domain.TQ_FIN_PRGCFSTATEMENTNEW
		err := mdb.db.NewSession().Where("ISVALID=? and REPORTTYPE = ? and ENTRYDATE between ?  and  ?", 1, transfer.REPORTTYPE_1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的现金流量数据出错:", zap.Any("err", err))
			return nil, err
		}

		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, v := range rows {
			r := new(domain.CASH_FLOW)

			compCode := v.Compcode
			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {
				r.Symbol = basicInfo.Symbol
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Reportyear = v.Reportyear                               //会计年度
				r.Reportdatetype = v.Reportdatetype                       //报告期类型
				r.Compcode = v.Compcode                                   //机构代码
				r.Bizcashinfl = v.Bizcashinfl                             //经营活动现金流入小计
				r.Bizcashoutf = v.Bizcashoutf                             //经营活动现金流出小计
				r.Mananetr = v.Mananetr                                   //经营现金流量净额
				r.Invcashinfl = v.Invcashinfl                             //投资活动现金流入小计
				r.Invcashoutf = v.Invcashoutf                             //投资活动现金流出小计
				r.Invnetcashflow = v.Invnetcashflow                       //投资现金流量净额
				r.Fincashinfl = v.Fincashinfl                             //筹资活动现金流入小计
				r.Fincashoutf = v.Fincashoutf                             //筹资活动现金流出小计
				r.Finnetcflow = v.Finnetcflow                             //筹资现金流量净额
				r.Cashnetr = v.Cashnetr                                   //现金及现金等价物净增加额

				results = append(results, r)

			}
		}

		return results, nil
	case "TQ_FIN_PRGFINMAININDEX": // 主要指标
		var results []*domain.KEY_INDICATOR
		var rows []*domain.TQ_FIN_PRGFINMAININDEX
		erri := mdb.db.NewSession().Where("ISVALID=? and REPORTTYPE = ? and ENTRYDATE between ?  and  ?", 1, transfer.REPORTTYPE_1, startDate, endDate).Find(&rows)
		if erri != nil {
			global.LOG.Error("获取时间间隔的主要指标数据出错:", zap.Any("err", erri))
			return nil, erri
		}
		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, errs := mdb.GetAllTqSkBasicInfo(ctx)
		if errs != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", errs))
			return nil, errs
		}

		// 1.先把要补充的数据，加载到结果集
		for _, o := range rows {
			r := new(domain.KEY_INDICATOR)

			compCode := o.Compcode
			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)

			if basicInfo != nil {
				symbol := basicInfo.Symbol //证券代码
				exchange := basicInfo.Exchange

				r.Symbol = symbol
				r.Compcode = compCode                           //机构代码
				r.Exchange = transfer.TransferExchane(exchange) //市场代码
				r.Reportyear = o.Reportyear                     //会计年度
				r.Reportdatetype = o.Reportdatetype             //报告期类型
				r.Epsbasic = o.Epsbasic                         //（一）基本每股收益
				r.Enddate = o.Enddate

				results = append(results, r)

			}
		}

		// 遍历结果集，设置相关值
		for _, v := range results {
			compCode := v.Compcode
			//2. 根据compCode 查询衍生财务指标(产品表)
			indicDatas, err := mdb.GetTqFinPrgIndicDataByCompCode(ctx, compCode)
			if err != nil {
				global.LOG.Error("获取 衍生财务指标(产品表)_V3(TQ_FIN_PRGINDICDATA) 数据出错", zap.Any("err", err))
				return nil, err
			}

			//3. 设置同一个compCode下的相同 报告期年度 和 报告期类型 的 衍生财务指标数据
			results = setIndicData(results, indicDatas)

			//4.根据compCode 查询 衍生财务指标副表(产品表)数据
			indicDatasSubs, err := mdb.GetTqFinPrgIndicDataSubByCompCode(ctx, compCode)
			if err != nil {
				global.LOG.Error("获取 衍生财务指标副表(产品表)_V3(TQ_FIN_PRGINDICDATASUB) 数据出错", zap.Any("err", err))
				return nil, err
			}

			//5.设置同一个compCode下的相同 报告期年度 和 报告期类型 的 衍生财务指标副表数据
			results = setIndicDatasSubs(results, indicDatasSubs)

		}

		return results, nil

	case "TQ_FIN_PROQINDIC": // 主要指标-单季度
		var results []*domain.KEY_INDICATOR_SQ
		var rows []*domain.TQ_FIN_PROQINDIC
		err := mdb.db.NewSession().Where("ISVALID=? and (REPORTTYPE = ? or REPORTTYPE = ?) and  ENTRYDATE between ?  and  ? ", 1, transfer.REPORTTYPE_1, transfer.REPORTTYPE_c3, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的主要指标-单季度数据出错:", zap.Any("err", err))
			return nil, err
		}

		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, erri := mdb.GetAllTqSkBasicInfo(ctx)
		if erri != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", erri))
			return nil, erri
		}

		for _, v := range rows {
			r := new(domain.KEY_INDICATOR_SQ)

			compCode := v.Compcode
			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)

			if basicInfo != nil {
				var tempRows []*domain.KEY_INDICATOR_SQ //每一个compCode对应一个结果集
				symbol := basicInfo.Symbol              //证券代码
				exchange := basicInfo.Exchange

				//取得基本每股收益
				subjects, errs := mdb.GetTqFinPrgPasqSubjectsByCompCode(ctx, compCode)
				if errs != nil {
					global.LOG.Error("获取 TQ_FIN_PRGPASQSUBJECTS 单季衍生利润科目(产品表）", zap.Any("err", errs))
					return nil, errs
				}

				//设置基本每股收益
				setIndicatorSqEpsBasic(rows, subjects)

				// 设置财务数据-主要指标-单季度
				r.Symbol = symbol
				r.Exchange = transfer.TransferExchane(exchange) //市场代码
				r.Reportyear = v.Reportyear                     //会计年度
				r.Reportdatetype = v.Reportdatetype             //报告期类型
				r.Compcode = v.Compcode                         //机构代码
				r.Epsbasic = v.Basiceps                         //（一）基本每股收益 厂商2022年5月份开始处理
				r.Roediluted = v.Roediluted                     //净资产收益率_摊薄
				r.Opncfps = v.Opncfps                           //每股经营活动产生的现金流量净额
				r.Snpmarginconms = v.Sgpmargin                  // 销售毛利率
				r.Opprort = v.Opprort                           // 营业利润率
				r.Roediluted = v.Roediluted                     //摊薄净资产收益率

				tempRows = append(tempRows, r)

				//累加
				results = append(results, tempRows...)

			}
		}

		return results, nil
	case "TQ_FIN_PRGCFSQSUBJECTS": // 企业单季度现金流
		var results []*domain.CASH_FLOW_SQ
		var rows []*domain.TQ_FIN_PRGCFSQSUBJECTS
		err := mdb.db.NewSession().Where("ISVALID=? and (REPORTTYPE = ? or REPORTTYPE = ?) and ENTRYDATE between ?  and  ? ", 1, transfer.REPORTTYPE_1, transfer.REPORTTYPE_c3, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的单季度现金流量数据出错:", zap.Any("err", err))
			return nil, err
		}

		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, v := range rows {
			r := new(domain.CASH_FLOW_SQ)

			compCode := v.Compcode
			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)

			if basicInfo != nil {
				r.Symbol = basicInfo.Symbol
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Reportyear = v.Reportyear                               //会计年度
				r.Reportdatetype = v.Reportdatetype                       //报告期类型
				r.Compcode = v.Compcode                                   //机构代码
				r.Bizcashinfl = v.Bizcashinflopi                          //经营活动现金流入小计
				r.Bizcashoutf = v.Bizcashoutfopo                          //经营活动现金流出小计
				r.Mananetr = v.Mananetr                                   //经营现金流量净额
				r.Invcashinfl = v.Invcashinflinvi                         //投资活动现金流入小计
				r.Invcashoutf = v.Invcashoutfinvo                         //投资活动现金流出小计
				r.Invnetcashflow = v.Invnetcashflow                       //投资现金流量净额
				r.Fincashinfl = v.Fincashinflfini                         //筹资活动现金流入小计
				r.Fincashoutf = v.Fincashoutffino                         //筹资活动现金流出小计
				r.Finnetcflow = v.Finnetcflow                             //筹资现金流量净额
				r.Cashnetr = v.Cashnetr                                   //现金及现金等价物净增加额

				results = append(results, r)

			}

		}
		return results, nil
	case "TQ_FIN_PRGPASQSUBJECTS": //企业利润 单季度
		var results []*domain.INCOME_STATEMENT_SQ
		var rows []*domain.TQ_FIN_PRGPASQSUBJECTS
		err := mdb.db.NewSession().Where("ISVALID=? and (REPORTTYPE = ? or REPORTTYPE = ?) and  ENTRYDATE between ?  and  ? ", 1, transfer.REPORTTYPE_1, transfer.REPORTTYPE_c3, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的企业利润单季度数据出错:", zap.Any("err", err))
			return nil, err
		}

		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, v := range rows {
			r := new(domain.INCOME_STATEMENT_SQ)
			compCode := v.Compcode
			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {
				r.Symbol = basicInfo.Symbol
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Reportyear = v.Reportyear                               //会计年度
				r.Reportdatetype = v.Reportdatetype                       //报告期类型
				r.Compcode = compCode                                     //机构代码
				r.Biztotinco = v.Bizinco                                  // 营业收入
				r.Biztotcost = v.Bizcost                                  //营业成本
				r.Manaexpe = v.Mgtexpe                                    //管理费用
				r.Salesexpe = v.Opexpe                                    //营业费用
				r.Finexpe = v.Finlexpe                                    //财务费用
				r.Perprofit = v.Opprofit                                  //营业利润
				r.Inveinco = v.Inveinco                                   // 投资收益
				r.Nonoreve = v.Nnonopi                                    //营业外收支净额
				r.Nonoexpe = v.Nonbizcost                                 //设置为 营业外收支净额
				r.Totprofit = v.Totprofit                                 //利润总额
				r.Netprofit = v.Netprofitconms                            //净利润

				results = append(results, r)
			}
		}

		return results, nil
	case "TQ_SK_FUNDAMENTALS": //最新指标
		var results []*domain.LATEST_INDICATOR
		var rows []*domain.TQ_SK_FUNDAMENTALS
		err := mdb.db.NewSession().Where("ISVALID = ? and  ENTRYDATE between ?  and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的最新指标数据出错:", zap.Any("err", err))
			return nil, err
		}

		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, f := range rows {
			r := new(domain.LATEST_INDICATOR)

			secode := f.Secode
			l := len(secode)
			symbol := secode[l-6:]

			basicInfo := getSkBasicInfoBySymbol(skBasicInfos, symbol)
			if basicInfo != nil {

				compCode := basicInfo.Compcode
				exchange := basicInfo.Exchange

				var rowsTmp []*domain.LATEST_INDICATOR //每一个compCode对应一个结果集

				basicEps := f.Basiceps     //每股收益
				naps := f.Naps             //每股净资产
				totalShare := f.Totalshare //总股本
				roe := f.Roe               //净资产收益率
				operCfps := f.Opercfps     //每股经营现金流
				npgrt := f.Npgrt           //净利润同比增长

				//获取主要财务指标信息
				mainIndexs, err1 := mdb.GetTqFinPrgFinMainIndexByCompCode(ctx, compCode)
				if err1 != nil {
					global.LOG.Error("获取主要财务指标(产品表）信息失败:", zap.Any("err", err1))

					return nil, err1
				}

				for _, m := range mainIndexs {

					r.Compcode = compCode
					r.Symbol = symbol
					r.Exchange = transfer.TransferExchane(exchange) //市场代码

					r.Basiceps = basicEps //每股收益
					r.Naps = naps         //每股净资产

					r.Totalshare = totalShare //总股本
					r.Roe = roe               //净资产收益率
					r.Opercfps = operCfps     //每股经营现金流
					r.Npgrt = npgrt           //净利润同比增长

					reportYear := m.Reportyear
					reportDateType := m.Reportdatetype

					r.Reportdatetype = reportDateType //报告期类型
					r.Reportyear = reportYear         //会计年度

					r.Epsbasicepscut = m.Epsbasicepscut //扣除非经常性损益后的基本每股收益

					r.Enddate = m.Enddate //业务主键

					rowsTmp = append(rowsTmp, r)
				}

				//获取 一般企业利润表信息
				stmns, err2 := mdb.GetTqFinPrgIncStatementNewByCompCode(ctx, compCode)
				if err2 != nil {
					global.LOG.Error("获取一般企业利润表信息失败:", zap.Any("err", err2))

					return nil, err2
				}

				//设置企业利润信息
				rowsTmp = setIncStatement(rowsTmp, stmns)

				//衍生财务指标
				indicDatas, err3 := mdb.GetTqFinPrgIndicDataByCompCode(ctx, compCode)
				if err3 != nil {
					global.LOG.Error("获取衍生财务指标信息失败:", zap.Any("err", err3))

					return nil, err3
				}

				//设置衍生财务指标信息
				rowsTmp = setIndicData4LatestIndicator(rowsTmp, indicDatas)

				// 衍生财务指标副表
				indicDataSub, err4 := mdb.GetTqFinPrgIndicDataSubByCompCode(ctx, compCode)
				if err4 != nil {
					global.LOG.Error("获取衍生财务指标副表失败:", zap.Any("err", err4))
					return nil, err4
				}

				// 设置衍生财务指标副表信息
				rowsTmp = setIndicDataSub4LatestIndicator(rowsTmp, indicDataSub)

				results = append(results, rowsTmp...)

			}

		}

		return results, err
	case "TQ_SK_IMPORTEVENT": //大事提醒
		var results []*domain.EVENT_REMIND
		var rows []*domain.TQ_SK_IMPORTEVENT
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的公司大事数据出错:", zap.Any("err", err))
			return nil, err
		}
		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, d := range rows {
			r := new(domain.EVENT_REMIND)
			compCode := d.Compcode

			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {
				r.Declaredate = d.Declaredate //公告日期
				r.Eventtext = d.Eventtext     //内容简介
				r.Symbol = basicInfo.Symbol
				r.Compcode = compCode                                     //机构代码
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Sourcetable = d.Sourcetable                             //栏目标识
				r.Eventtitle = d.Eventtitle                               //标题
				r.Rank = d.Rank                                           //排序

				results = append(results, r)
			}
		}
		return results, nil
	case "TQ_SK_BONUS2": //分红融资
		var results []*domain.BONUS_FINANCING
		var rows []*domain.TQ_SK_BONUS
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ? and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的分红融资数据出错:", zap.Any("err", err))
			return nil, err
		}
		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, b := range rows {
			r := new(domain.BONUS_FINANCING)
			compCode := b.Compcode

			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {

				r.Symbol = basicInfo.Symbol                               //证券编码
				r.Compcode = compCode                                     //机构编码
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Recorddate = b.Recorddate                               //权益登记日
				r.Exrightdate = b.Exrightdate                             //除息日
				r.Divibegdate = b.Divibegdate                             //红利发放日
				r.Taxcdividend = b.Taxcdividend                           //税后红利
				r.Bonusimpdate = b.Bonusimpdate                           //公布日期
				r.Capstkbasdate = b.Capstkbasdate                         //红利结转份日
				r.Diviimpmarkd = b.Diviimpmarkd                           //进展说明
				r.Bonusyear = b.Bonusyear                                 // 分红实施年度
				r.Dividtype = b.Dividtype                                 //权益日期类型
				r.Divitype = b.Divitype                                   //权益类型

				results = append(results, r)
			}
		}
		return results, nil
	case "TQ_SK_BONUS": // 分红派送
		var results []*domain.DIVIDEND
		var rows []*domain.TQ_SK_BONUS
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ? and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的分红融资数据出错:", zap.Any("err", err))
			return nil, err
		}
		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, b := range rows {
			r := new(domain.DIVIDEND)
			compCode := b.Compcode

			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {
				r.Compcode = compCode //机构代码
				r.Symbol = basicInfo.Symbol
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Bonusimpdate = b.Bonusimpdate                           //分红实施公告日
				r.Cdividend = b.Cdividend                                 //'税前红利（报价币种)
				r.Exrightdate = b.Exrightdate                             //除权除息日
				r.Bonusyear = b.Bonusyear                                 //分红实施年度
				r.Dividtype = b.Dividtype                                 //权益日期类型
				r.Divitype = b.Divitype                                   //权益类型

				results = append(results, r)
			}

		}

		return results, nil
	case "TQ_SK_FINMRGNINFO": //融资融劵
		var results []*domain.MARGIN
		var rows []*domain.TQ_SK_FINMRGNINFO
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的分红融资数据出错:", zap.Any("err", err))
			return nil, err
		}
		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, b := range rows {
			r := new(domain.MARGIN)
			symbol := b.Symbol

			basicInfo := getSkBasicInfoBySymbol(skBasicInfos, symbol)
			if basicInfo != nil {
				r.Compcode = basicInfo.Compcode
				r.Symbol = symbol
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Finbalance = b.Finbalance                               //融资余额'
				r.Finbuyamt = b.Finbuyamt                                 ///融资买入额
				r.Tradedate = b.Tradedate                                 //交易日期
				r.Mrggbal = b.Mrggbal                                     //融券余量金额
				r.Mrgnresqty = b.Mrgnresqty                               //融券余量
				r.Mrgnsellamt = b.Mrgnsellamt                             //融券卖出量
				r.Finmrghbal = b.Finmrghbal                               //融资融券余额

				results = append(results, r)
			}

		}

		return results, nil
	case "TQ_EXPT_SKSTATN": //盈利预测
		var results []*domain.PROFIT_FORECAST
		var rows []*domain.TQ_EXPT_SKSTATN
		err := mdb.db.NewSession().Where("ENTRYDATE between ?  and  ?", startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的盈利预测数据出错:", zap.Any("err", err))
			return nil, err
		}
		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}
		for _, s := range rows {
			symbol := s.Symbol

			basicInfo := getSkBasicInfoBySymbol(skBasicInfos, symbol)

			if basicInfo != nil {

				exchange := basicInfo.Exchange
				compCode := basicInfo.Compcode

				exc := transfer.TransferExchane(exchange) //市场代码

				//一致预测一期
				r1 := new(domain.PROFIT_FORECAST)

				r1.Symbol = symbol
				r1.Compcode = compCode
				r1.Exchange = exc //市场代码

				tendDate := ""
				if len(s.Tenddate) >= 4 {
					tendDate = s.Tenddate[:4]
				}

				if len(tendDate) > 0 {
					r1.Exptyear = tendDate           //年度
					r1.Publishdate = s.Publishdate   //研报日期
					r1.Opermincome = s.Tmbizincome   //一致预期营业收入（一期）
					r1.Retamaxprofits = s.Tnetprofit //一致预期净利润（一期）
					r1.Epsmaxfore = s.Teps           //一致预期每股收益(一期）

					results = append(results, r1)
				}

				//一致预测二期
				r2 := new(domain.PROFIT_FORECAST)

				r2.Symbol = symbol
				r2.Compcode = compCode
				r2.Exchange = exc //市场代码

				nendDate := ""
				if len(s.Nenddate) >= 4 {
					nendDate = s.Nenddate[:4]
				}
				if len(nendDate) > 0 {
					r2.Exptyear = nendDate           //年度
					r2.Publishdate = s.Publishdate   //研报日期
					r2.Opermincome = s.Nmbizincome   //一致预期营业收入（二期）
					r2.Retamaxprofits = s.Nnetprofit //一致预期净利润（二期）
					r2.Epsmaxfore = s.Neps           //一致预期每股收益（二期）

					results = append(results, r2)
				}

				//一致预测三期
				r3 := new(domain.PROFIT_FORECAST)

				r3.Symbol = symbol
				r3.Compcode = compCode
				r3.Exchange = exc //市场代码

				yanendDate := ""
				if len(s.Yanenddate) >= 4 {
					yanendDate = s.Yanenddate[:4]
				}

				if len(yanendDate) > 0 {
					r3.Exptyear = yanendDate           //年度
					r3.Publishdate = s.Publishdate     //研报日期
					r3.Opermincome = s.Yanmbizincome   //一致预期营业收入(三期)
					r3.Retamaxprofits = s.Yannetprofit //一致预期净利润（三期）
					r3.Epsmaxfore = s.Yaneps           //一致预期每股收益（三期）

					results = append(results, r3)
				}

			}

		}

		return results, nil
	case "TQ_EXPT_SKINVRATING2": //机构评级统计
		var results []*domain.RATING_COUNT
		var rows []*domain.TQ_EXPT_SKINVRATING
		errs := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ?", 1, startDate, endDate).Find(&rows)
		if errs != nil {
			global.LOG.Error("获取时间间隔的机构评级数据出错:", zap.Any("err", errs))
			return nil, errs
		}

		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, erri := mdb.GetAllTqSkBasicInfo(ctx)
		if erri != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", erri))
			return nil, erri
		}

		for _, s := range rows {
			symbol := s.Symbol
			basicInfo := getSkBasicInfoBySymbol(skBasicInfos, symbol)
			if basicInfo != nil {
				compCode := basicInfo.Compcode
				exchange := basicInfo.Exchange

				//1.评级有效期为三个月的
				r3 := new(domain.RATING_COUNT)
				r3.Symbol = symbol                               //证券代码
				r3.Compcode = compCode                           //机构代码
				r3.Exchange = transfer.TransferExchane(exchange) //市场代码

				r3.Ratingvalid = transfer.RATINGVALID_3MONTH //评级有效期三个月

				//买入数量
				buy3Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_BUY, transfer.RATINGVALID_3MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_BUY), zap.String("RatingValid", transfer.RATINGVALID_3MONTH), zap.Any("err", err))
					buy3Cnt = 0 //出错设置为0
				}
				r3.Buy = buy3Cnt                      //买入数量
				r3.Stdrating = transfer.STDRATING_BUY //买入

				//增持数量
				enlarge3Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_ENLARGE, transfer.RATINGVALID_3MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_ENLARGE), zap.String("RatingValid", transfer.RATINGVALID_3MONTH), zap.Any("err", err))
					enlarge3Cnt = 0 //出错设置为0
				}
				r3.Enlarge = enlarge3Cnt                                       //增持数量
				r3.Stdrating = r3.Stdrating + "," + transfer.STDRATING_ENLARGE //增持

				//中性数量
				neutral3Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_NEUTRAL, transfer.RATINGVALID_3MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_NEUTRAL), zap.String("RatingValid", transfer.RATINGVALID_3MONTH), zap.Any("err", err))
					neutral3Cnt = 0 //出错设置为0
				}
				r3.Neutral = neutral3Cnt                                       //中性数量
				r3.Stdrating = r3.Stdrating + "," + transfer.STDRATING_NEUTRAL // 中性

				//减持数量
				reduce3Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_REDUCE, transfer.RATINGVALID_3MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_REDUCE), zap.String("RatingValid", transfer.RATINGVALID_3MONTH), zap.Any("err", err))
					reduce3Cnt = 0 //出错设置为0
				}
				r3.Reduce = reduce3Cnt                                        //减持数量
				r3.Stdrating = r3.Stdrating + "," + transfer.STDRATING_REDUCE //减持

				//卖出数量
				sell3Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_SELL, transfer.RATINGVALID_3MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_SELL), zap.String("RatingValid", transfer.RATINGVALID_3MONTH), zap.Any("err", err))
					sell3Cnt = 0 //出错设置为0
				}
				r3.Sell = sell3Cnt                                          //卖出数量
				r3.Stdrating = r3.Stdrating + "," + transfer.STDRATING_SELL //卖出

				// 增加评级有效期3个月的记录
				results = append(results, r3)

				//2.评级有效期为六个月的
				r6 := new(domain.RATING_COUNT)
				r6.Symbol = symbol                               //证券代码
				r6.Compcode = compCode                           //机构代码
				r6.Exchange = transfer.TransferExchane(exchange) //市场代码

				r6.Ratingvalid = transfer.RATINGVALID_6MONTH //评级有效期六个月

				//买入数量
				buy6Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_BUY, transfer.RATINGVALID_6MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_BUY), zap.String("RatingValid", transfer.RATINGVALID_6MONTH), zap.Any("err", err))

					buy6Cnt = 0 //出错设置为0
				}
				r6.Buy = buy6Cnt                      //买入数量
				r6.Stdrating = transfer.STDRATING_BUY //买入

				//增持数量
				enlarge6Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_ENLARGE, transfer.RATINGVALID_6MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_ENLARGE), zap.String("RatingValid", transfer.RATINGVALID_6MONTH), zap.Any("err", err))

					enlarge6Cnt = 0 //出错设置为0
				}
				r6.Enlarge = enlarge6Cnt                                       //增持数量
				r6.Stdrating = r6.Stdrating + "," + transfer.STDRATING_ENLARGE //增持

				//中性数量
				neutral6Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_NEUTRAL, transfer.RATINGVALID_6MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_NEUTRAL), zap.String("RatingValid", transfer.RATINGVALID_6MONTH), zap.Any("err", err))

					neutral6Cnt = 0 //出错设置为0
				}
				r6.Neutral = neutral6Cnt                                       //中性数量
				r6.Stdrating = r6.Stdrating + "," + transfer.STDRATING_NEUTRAL // 中性

				//减持数量
				reduce6Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_REDUCE, transfer.RATINGVALID_6MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_REDUCE), zap.String("RatingValid", transfer.RATINGVALID_6MONTH), zap.Any("err", err))

					reduce6Cnt = 0 //出错设置为0
				}
				r6.Reduce = reduce6Cnt                                        //减持数量
				r6.Stdrating = r6.Stdrating + "," + transfer.STDRATING_REDUCE //减持

				//卖出数量
				sell6Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_SELL, transfer.RATINGVALID_6MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_SELL), zap.String("RatingValid", transfer.RATINGVALID_6MONTH), zap.Any("err", err))

					sell6Cnt = 0 //出错设置为0
				}
				r6.Sell = sell6Cnt                                          //卖出数量
				r6.Stdrating = r6.Stdrating + "," + transfer.STDRATING_SELL //卖出

				// 增加评级有效期6个月的记录
				results = append(results, r6)

				//3.评级有效期为十二个月的
				r12 := new(domain.RATING_COUNT)
				r12.Symbol = symbol                               //证券代码
				r12.Compcode = compCode                           //机构代码
				r12.Exchange = transfer.TransferExchane(exchange) //市场代码

				r12.Ratingvalid = transfer.RATINGVALID_12MONTH //评级有效期十二个月

				//买入数量
				buy12Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_BUY, transfer.RATINGVALID_12MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_BUY), zap.String("RatingValid", transfer.RATINGVALID_12MONTH), zap.Any("err", err))

					buy12Cnt = 0 //出错设置为0
				}
				r12.Buy = buy12Cnt                     //买入数量
				r12.Stdrating = transfer.STDRATING_BUY //买入

				//增持数量
				enlarge12Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_ENLARGE, transfer.RATINGVALID_12MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_ENLARGE), zap.String("RatingValid", transfer.RATINGVALID_12MONTH), zap.Any("err", err))

					enlarge12Cnt = 0 //出错设置为0
				}
				r12.Enlarge = enlarge12Cnt                                       //增持数量
				r12.Stdrating = r12.Stdrating + "," + transfer.STDRATING_ENLARGE //增持

				//中性数量
				neutral12Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_NEUTRAL, transfer.RATINGVALID_12MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_NEUTRAL), zap.String("RatingValid", transfer.RATINGVALID_12MONTH), zap.Any("err", err))

					neutral12Cnt = 0 //出错设置为0
				}
				r12.Neutral = neutral12Cnt                                       //中性数量
				r12.Stdrating = r12.Stdrating + "," + transfer.STDRATING_NEUTRAL // 中性

				//减持数量
				reduce12Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_REDUCE, transfer.RATINGVALID_12MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_REDUCE), zap.String("RatingValid", transfer.RATINGVALID_12MONTH), zap.Any("err", err))

					reduce12Cnt = 0 //出错设置为0
				}
				r12.Reduce = reduce12Cnt                                        //减持数量
				r12.Stdrating = r12.Stdrating + "," + transfer.STDRATING_REDUCE //减持

				//卖出数量
				sell12Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_SELL, transfer.RATINGVALID_12MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_SELL), zap.String("RatingValid", transfer.RATINGVALID_12MONTH), zap.Any("err", err))

					sell12Cnt = 0 //出错设置为0
				}
				r12.Sell = sell12Cnt                                          //卖出数量
				r12.Stdrating = r12.Stdrating + "," + transfer.STDRATING_SELL //卖出

				// 增加评级有效期12个月的记录
				results = append(results, r12)

				//4.评级有效期为十八个月的
				r18 := new(domain.RATING_COUNT)
				r18.Symbol = symbol                               //证券代码
				r18.Compcode = compCode                           //机构代码
				r18.Exchange = transfer.TransferExchane(exchange) //市场代码

				r18.Ratingvalid = transfer.RATINGVALID_18MONTH //评级有效期十八个月

				//买入数量
				buy18Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_BUY, transfer.RATINGVALID_18MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_BUY), zap.String("RatingValid", transfer.RATINGVALID_18MONTH), zap.Any("err", err))

					buy18Cnt = 0 //出错设置为0
				}
				r18.Buy = buy18Cnt                     //买入数量
				r18.Stdrating = transfer.STDRATING_BUY //买入

				//增持数量
				enlarge18Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_ENLARGE, transfer.RATINGVALID_18MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_ENLARGE), zap.String("RatingValid", transfer.RATINGVALID_18MONTH), zap.Any("err", err))

					enlarge18Cnt = 0 //出错设置为0
				}
				r18.Enlarge = enlarge18Cnt                                       //增持数量
				r18.Stdrating = r18.Stdrating + "," + transfer.STDRATING_ENLARGE //增持

				//中性数量
				neutral18Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_NEUTRAL, transfer.RATINGVALID_18MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_NEUTRAL), zap.String("RatingValid", transfer.RATINGVALID_18MONTH), zap.Any("err", err))

					neutral18Cnt = 0 //出错设置为0
				}
				r18.Neutral = neutral18Cnt                                       //中性数量
				r18.Stdrating = r18.Stdrating + "," + transfer.STDRATING_NEUTRAL // 中性

				//减持数量
				reduce18Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_REDUCE, transfer.RATINGVALID_18MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_REDUCE), zap.String("RatingValid", transfer.RATINGVALID_18MONTH), zap.Any("err", err))

					reduce18Cnt = 0 //出错设置为0
				}
				r18.Reduce = reduce18Cnt                                        //减持数量
				r18.Stdrating = r18.Stdrating + "," + transfer.STDRATING_REDUCE //减持

				//卖出数量
				sell18Cnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_SELL, transfer.RATINGVALID_18MONTH)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_SELL), zap.String("RatingValid", transfer.RATINGVALID_18MONTH), zap.Any("err", err))

					sell18Cnt = 0 //出错设置为0
				}
				r18.Sell = sell18Cnt                                          //卖出数量
				r18.Stdrating = r18.Stdrating + "," + transfer.STDRATING_SELL //卖出

				// 增加评级有效期18个月的记录
				results = append(results, r18)

				//5.评级有效期为无具体期限的
				rNO := new(domain.RATING_COUNT)
				rNO.Symbol = symbol                               //证券代码
				rNO.Compcode = compCode                           //机构代码
				rNO.Exchange = transfer.TransferExchane(exchange) //市场代码

				rNO.Ratingvalid = transfer.RATINGVALID_NO //评级有效期无具体期限的

				//买入数量
				buyNOCnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_BUY, transfer.RATINGVALID_NO)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_BUY), zap.String("RatingValid", transfer.RATINGVALID_NO), zap.Any("err", err))

					buyNOCnt = 0 //出错设置为0
				}
				rNO.Buy = buyNOCnt                     //买入数量
				rNO.Stdrating = transfer.STDRATING_BUY //买入

				//增持数量
				enlargeNOCnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_ENLARGE, transfer.RATINGVALID_NO)
				if err != nil {
					global.LOG.Error("获取标准评级和评级有效期的机构个数出错:%v:", zap.String("StdRating", transfer.STDRATING_REDUCE), zap.String("RatingValid", transfer.RATINGVALID_18MONTH), zap.Any("err", err))
					enlargeNOCnt = 0 //出错设置为0
				}
				rNO.Enlarge = enlargeNOCnt                                       //增持数量
				rNO.Stdrating = rNO.Stdrating + "," + transfer.STDRATING_ENLARGE //增持

				//中性数量
				neutralNOCnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_NEUTRAL, transfer.RATINGVALID_NO)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_NEUTRAL), zap.String("RatingValid", transfer.RATINGVALID_NO), zap.Any("err", err))

					neutral18Cnt = 0 //出错设置为0
				}
				rNO.Neutral = neutralNOCnt                                       //中性数量
				rNO.Stdrating = rNO.Stdrating + "," + transfer.STDRATING_NEUTRAL // 中性

				//减持数量
				reduceNOCnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_REDUCE, transfer.RATINGVALID_NO)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_REDUCE), zap.String("RatingValid", transfer.RATINGVALID_NO), zap.Any("err", err))

					reduceNOCnt = 0 //出错设置为0
				}
				rNO.Reduce = reduceNOCnt                                        //减持数量
				rNO.Stdrating = rNO.Stdrating + "," + transfer.STDRATING_REDUCE //减持

				//卖出数量
				sellNOCnt, err := mdb.GetStdRatingCounts(ctx, symbol, transfer.STDRATING_SELL, transfer.RATINGVALID_NO)
				if err != nil {
					global.LOG.Error("获取相关标准评级和评级有效期的机构个数出错:", zap.String("StdRating", transfer.STDRATING_SELL), zap.String("RatingValid", transfer.RATINGVALID_NO), zap.Any("err", err))

					sellNOCnt = 0 //出错设置为0
				}
				rNO.Sell = sellNOCnt                                          //卖出数量
				rNO.Stdrating = rNO.Stdrating + "," + transfer.STDRATING_SELL //卖出

				// 增加评级有效期12个月的记录
				results = append(results, rNO)

			}
		}
		return results, nil
	case "TQ_EXPT_SKINVRATING":
		var results []*domain.RATING
		var rows []*domain.TQ_EXPT_SKINVRATING
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的机构评级数据出错:", zap.Any("err", err))
			return nil, err
		}

		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, s := range rows {
			if s.Stdrating != "" {
				r := new(domain.RATING)
				symbol := s.Symbol
				basicInfo := getSkBasicInfoBySymbol(skBasicInfos, symbol)
				if basicInfo != nil {
					r.Symbol = symbol                                         //证券代码
					r.Compcode = basicInfo.Compcode                           //机构编码
					r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码

					r.Rating = s.Stdrating        //最新评级-->标准评级
					r.Compname = s.Compname       //评级机构名称 研究机构
					r.Lastrating = s.Stdrating    //上次评级-->标准评级
					r.Radjustdir = s.Radjustdir   //评级调整方向
					r.Reportdate = s.Reportdate   // 研报日期
					r.Skcode = s.Skcode           //个股预测内码
					r.Analystname = s.Analystname //研究员
					r.Ratingvalid = s.Ratingvalid //评级有效期

					results = append(results, r)

				}
			}
		}
		return results, nil
	case "TQ_COMP_INFO": //公司基本情况
		var results []*domain.COMPANY_PROFILE
		var rows []*domain.TQ_COMP_INFO
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的公司基本情况数据出错:", zap.Any("err", err))
			return nil, err
		}
		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, c := range rows {
			r := new(domain.COMPANY_PROFILE)
			compCode := c.Compcode
			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {
				r.Compcode = compCode                                     //机构代码
				r.Symbol = basicInfo.Symbol                               //证券代码
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Listdate = basicInfo.Listdate                           //上市日期
				r.Compname = c.Compname                                   //公司名称
				r.Regname = c.Region                                      //所属地域
				r.Comptype = c.Comptype1                                  //当前行业
				r.Legrep = c.Legrep                                       //法人代表
				r.Regcapital = c.Regcapital                               //注册资金
				r.Regaddr = c.Regaddr                                     //注册地址
				r.Majorbiz = c.Majorbiz                                   //主要业务
				r.Bizscope = c.Bizscope                                   //经营范围

				results = append(results, r)
			}
		}

		return results, nil
	case "TQ_SK_BUSIINFO":
		cache := make(map[string]string)
		var results []*domain.MAIN_COMPOSITION
		var rows []*domain.TQ_SK_BUSIINFO
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ? ", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的公司主要业务数据出错:", zap.Any("err", err))
			return nil, err
		}

		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, o := range rows {
			r := new(domain.MAIN_COMPOSITION)
			compCode := o.Compcode
			r.Compcode = compCode //机构代码
			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)

			if basicInfo != nil {
				r.Compcode = compCode                                     //机构编码
				r.Symbol = basicInfo.Symbol                               //证券编码
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码

				//根据compCode 查询 TQ_FIN_PRGINCSTATEMENTNEW表：一般企业利润表(新准则产品表)
				statementNews, err1 := mdb.GetTqFinPrgIncStatementNewByCompCode(ctx, compCode)
				if err1 != nil {
					err = err1
				}

				for _, s := range statementNews { //可能存在reportType=1 但是 reportDateType为1，2，3，4的四条数据

					reportYear := s.Reportyear //会计年度 例如：2021
					cacheKey := reportYear + compCode

					has, _ := cache[cacheKey]
					if has != "1" {
						s = getRecentReportDateFinPrgIncStatementNew(statementNews, reportYear)

						if s != nil {
							bizTotCost := s.Biztotcost //营业总成本
							perProfit := s.Perprofit   //营业利润

							r.Biztotcost = bizTotCost
							r.Perprofit = perProfit
							r.Reportyear = reportYear
						}

						infoArray := getSkBizInfo(reportYear, rows, r) //行业分类信息
						if infoArray != nil {
							productInfo, err2 := json.Marshal(infoArray)
							if err2 != nil {
								err = err2
							}
							r.Productinfo = string(productInfo) //产品业务信息

							if len(r.Productinfo) > 0 {
								results = append(results, r)
								cache[cacheKey] = "1" //已经计算过了
							}
						}
					}

				}

			}

		}

		return results, nil
	case "TQ_COMP_MANAGER": // 公司高管
		var results []*domain.COMPANY_EXECUTIVES
		var rows []*domain.TQ_COMP_MANAGER
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ? ", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的公司高管数据出错:", zap.Any("err", err))
			return nil, err
		}
		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, m := range rows {
			r := new(domain.COMPANY_EXECUTIVES)
			compCode := m.Compcode
			r.Compcode = compCode //机构代码
			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {
				personalCode := m.Personalcode //人员代码

				r.Symbol = basicInfo.Symbol                               //证券代码
				r.Compcode = compCode                                     //机构编码
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Cname = m.Cname                                         //姓名
				r.Actdutyname = m.Actdutyname                             //职务
				r.Begindate = m.Begindate                                 //任职日期
				r.Personalcode = m.Personalcode                           //人物代码
				r.Postype = m.Postype                                     //职位属性
				r.Nowstatus = m.Nowstatus                                 //当前状态

				personRecord, _ := mdb.GetTqCompPersonRecordByPersonalCode(ctx, personalCode)
				if personRecord != nil {
					r.Gender = personRecord.Gender //性别
					if len(personRecord.Birthday) >= 4 {
						r.Birthday = personRecord.Birthday[:4] //年龄
					}

					r.Degree = personRecord.Degree //学历
					r.Memo = personRecord.Memo     //简介
				}

				results = append(results, r)
			}

		}

		return results, nil
	case "TQ_SK_SHARESTRUCHG2": //股本变动数据
		var results []*domain.EQUITY_STRUCTURE_CHANGE
		var rows []*domain.TQ_SK_SHARESTRUCHG
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的股本变动数据出错:", zap.Any("err", err))
			return nil, err
		}
		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}
		for _, d := range rows {
			r := new(domain.EQUITY_STRUCTURE_CHANGE)
			compCode := d.Compcode

			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {
				r.Symbol = basicInfo.Symbol
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Compcode = compCode
				r.Begindate = d.Begindate         //变动开始日期
				r.Shchgrsn = d.Shchgrsn           //股份变动原因
				r.Totalshare = d.Totalshare       //总股本
				r.Totalsharechg = d.Totalsharechg //总股本变动数量
				r.Skchgexp = d.Skchgexp           //变动日期股本说明 变动方向
				r.Exrightdate = d.Exrightdate     //除权除息日

				results = append(results, r)
			}
		}
		return results, nil
	case "TQ_SK_SHARESTRUCHG": // 股本结构信息

		var results []*domain.EQUITY_STRUCTURE
		var rows []*domain.TQ_SK_SHARESTRUCHG
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的股本结构变化数据出错:", zap.Any("err", err))
			return nil, err
		}

		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, d := range rows {
			r := new(domain.EQUITY_STRUCTURE)
			compCode := d.Compcode
			r.Compcode = compCode

			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {
				r.Symbol = basicInfo.Symbol
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码

				r.Totalshare = d.Totalshare    //总股本
				r.Circskamt = d.Circskamt      //已流通股份合计
				r.Circskrto = d.Circskrto      //已上市流通股占比
				r.Circskamtnolim = d.Circskamt //无限售流通股份
				r.Circskrtonolim = d.Circskrto //无限售流通股份占比
				r.Circhamt = d.Circhamt        //境外上市流通股
				r.Hsharerto = d.Hsharerto      //境外上市流通股占比
				r.Ncircamt = d.Ncircamt        //未流通股份合计
				r.Nonnegskrto = d.Nonnegskrto  //未流通股份合计占比
				r.Circaamt = d.Circaamt        //已上市流通A股
				r.Asharerto = d.Asharerto      //已上市流通A股占比
				r.Circbamt = d.Circbamt        //已上市流通B股
				r.Bsharerto = d.Bsharerto      //已上市流通B股占比
				r.Ncircamt1 = d.Ncircamt       //未流通股份
				r.Nonnegskrto1 = d.Nonnegskrto //未流通股份占比
				r.Begindate = d.Begindate      //变动起始日
				r.Exrightdate = d.Exrightdate  //除权除息日
				r.Publishdate = d.Publishdate  //信息发布日期

				results = append(results, r)
			}
		}

		return results, nil
	case "TQ_SK_SHAREHOLDERNUM":

		var results []*domain.HOLDER_CHANGE
		var rows []*domain.TQ_SK_SHAREHOLDERNUM
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的股东变动数据出错:", zap.Any("err", err))
			return nil, err
		}
		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, s := range rows {
			r := new(domain.HOLDER_CHANGE)

			compCode := s.Compcode
			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {

				r.Symbol = basicInfo.Symbol                               //证券代码
				r.Compcode = compCode                                     //机构代码
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码

				totalShAmt := s.Totalshamt //股东总户数
				totalShRto := s.Totalshrto // 股东总户数交上期增减

				r.Totalshamt = totalShAmt // 股东人数

				if totalShAmt != "0" && totalShAmt != "0.0" && totalShAmt != "null" && totalShAmt != "" {
					// 较上期变化： TOTALSHRTO/TOTALSHAMT
					totalShRtoDec, _ := decimal.NewFromString(totalShRto)
					totalShAmtDec, _ := decimal.NewFromString(totalShAmt)
					chgrtoDec := totalShRtoDec.Div(totalShAmtDec)
					totalShchgrto := chgrtoDec.String()

					r.Totalshchgrto = totalShchgrto //较上期变化
				}

				kavgsh := s.Kavgsh
				r.Kavgsh = kavgsh //户均持股数

				endT := s.Enddate //截止日期
				r.Enddate = endT

				//根据endDate和seCode查询TQ_QT_SKDAILYPRICE股票历史交易日信息
				skdailyPrices, err1 := mdb.GetSkDailyPricesBySeCodeAndTradeDate(ctx, basicInfo.Secode, endT)
				if err1 != nil {
					global.LOG.Error("获取股票历史交易日信息出错:", zap.Any("err", err))
					//return nil, err
				}

				if skdailyPrices != nil && len(skdailyPrices) > 0 {
					sdp := skdailyPrices[0]

					tclose := sdp.Tclose
					r.Tclose = tclose //收盘价

					//人均持股金额(元):公式：TCLOSE收盘价*KAVGSH户均持股数
					tcloseDec, _ := decimal.NewFromString(tclose)
					kavgshDec, _ := decimal.NewFromString(kavgsh)
					kavgholdamtDec := tcloseDec.Mul(kavgshDec)

					kavgholdamt := kavgholdamtDec.String()

					r.Kavgholdamt = kavgholdamt //人均持股金额(元)

				}

				results = append(results, r)
			}

		}

		return results, nil
	case "TQ_SK_OTSHOLDER": //十大流通股股东
		var results []*domain.TEN_CIRCULATING_SHARES_HOLDER
		var rows []*domain.TQ_SK_OTSHOLDER
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的十大流通股股东数据出错:", zap.Any("err", err))
			return nil, err
		}
		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, o := range rows {
			r := new(domain.TEN_CIRCULATING_SHARES_HOLDER)
			compCode := o.Compcode

			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {
				r.Symbol = basicInfo.Symbol                               //证券代码
				r.Compcode = compCode                                     //机构编码
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Shholdername = o.Shholdername                           //股东名称
				r.Holderrto = o.Holderrto                                 //占比
				r.Pctofflotshares = o.Pctofflotshares                     //占流通股比例
				r.Holdersumchg = o.Holdersumchg                           //增减
				r.Holdersumchgrate = o.Holdersumchgrate                   //增减幅度
				r.Shholdercode = o.Shholdercode                           //股东代码
				r.Holderamt = o.Holderamt                                 //持股数
				//r.Publishdate = o.Publishdate                 //信息发布日期
				r.Publishdate = o.Enddate //信息发布日期
				r.Enddate = o.Enddate     //截止日期
				r.Rank = o.Rank           //股东排名

				results = append(results, r)
			}
		}

		return results, nil
	case "TQ_SK_SHAREHOLDER":
		var results []*domain.TEN_HOLDER
		var rows []*domain.TQ_SK_SHAREHOLDER
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的十大股东数据出错:", zap.Any("err", err))
			return nil, err
		}

		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}

		for _, t := range rows {
			r := new(domain.TEN_HOLDER)
			compCode := t.Compcode

			basicInfo := getSkBasicInfoByCompCode(skBasicInfos, compCode)
			if basicInfo != nil {

				r.Symbol = basicInfo.Symbol
				r.Compcode = compCode
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Shholdername = t.Shholdername                           //股东名称
				r.Holderamt = t.Holderamt                                 //持股数
				r.Holderrto = t.Holderrto                                 //占比
				r.Curchg = t.Curchg                                       //增减
				r.Shholdercode = t.Shholdercode                           //股东代码
				r.Publishdate = t.Enddate                                 //信息发布日期
				r.Enddate = t.Enddate                                     //截止日期
				r.Rank = t.Rank                                           //股东排名
				curChgDec, _ := decimal.NewFromString(t.Curchg)
				holderAmtDec, _ := decimal.NewFromString(t.Holderamt)
				sumDec := holderAmtDec.Add(curChgDec)
				if sumDec.String != nil && sumDec.String() != "0" && sumDec.String() != "0.00" && sumDec.String() != "" {
					curChgRageDec := curChgDec.Div(sumDec) //本期变动数量增减幅度:	CURCHG本期变动数量/( HOLDERAMT持股数量 + CURCHG本期变动数量)*100%
					currChgRate := curChgRageDec.String()
					r.Curchgrate = currChgRate //增减幅度
				}

				circAmt := t.Circamt //流通股
				if circAmt != "0.00" && circAmt != "null" && circAmt != "" && circAmt != "0" {
					circAmtDec, _ := decimal.NewFromString(circAmt)
					rtoDec := holderAmtDec.Div(circAmtDec)

					r.Holdcircskamtrto = rtoDec.String() //占流通股比
				}

				results = append(results, r)

			}

		}

		return results, nil
	case "TQ_QT_BIZUNITTRDINFO": //龙虎榜
		var results []*domain.RANK_LIST
		var rows []*domain.TQ_QT_BIZUNITTRDINFO
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的龙虎榜数据出错:", zap.Any("err", err))
			return nil, err
		}

		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}
		for _, b := range rows {
			r := new(domain.RANK_LIST)
			symbol := b.Symbol

			basicInfo := getSkBasicInfoBySymbol(skBasicInfos, symbol)

			if basicInfo != nil {
				r.Symbol = symbol                                         //证券代码
				r.Compcode = basicInfo.Compcode                           //机构编码
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Tradedate = b.Tradedate                                 //交易日期
				r.Bizsunitname = b.Bizsunitname                           //营业部名称
				r.Amount = b.Amount                                       //成交金额
				r.Buyamt = b.Buyamt                                       //买入金额
				r.Saleamt = b.Saleamt                                     //卖出金额
				r.Chgtype = b.Chgtype                                     // 备注
				r.Bizsunitcode = b.Bizsunitcode                           //营业部代码
				r.Transdir = b.Transdir                                   //买卖方向

				results = append(results, r)
			}
		}

		return results, nil
	case "TQ_QT_BLOCKTRADE": //大宗交易
		var results []*domain.BLOCK_TRADING
		var rows []*domain.TQ_QT_BLOCKTRADE
		err := mdb.db.NewSession().Where("ISVALID = ? and ENTRYDATE between ?  and  ?", 1, startDate, endDate).Find(&rows)
		if err != nil {
			global.LOG.Error("获取时间间隔的大宗交易数据出错:", zap.Any("err", err))
			return nil, err
		}

		//获取所有证券信息，用于获取symbol和exchange
		skBasicInfos, err := mdb.GetAllTqSkBasicInfo(ctx)
		if err != nil {
			global.LOG.Error("查询所有【TQ_SK_BASICINFO】信息出错:", zap.Any("err", err))
			return nil, err
		}
		for _, b := range rows {
			r := new(domain.BLOCK_TRADING)
			symbol := b.Symbol

			basicInfo := getSkBasicInfoBySymbol(skBasicInfos, symbol)
			if basicInfo != nil {
				r.Symbol = symbol                                         //证券代码
				r.Compcode = basicInfo.Compcode                           //机构编码
				r.Exchange = transfer.TransferExchane(basicInfo.Exchange) //市场代码
				r.Tradedate = b.Tradedate                                 //交易日期
				r.Tradeprice = b.Tradeprice                               //成交价格
				r.Volume = b.Volume                                       //成交数量
				r.Amount = b.Amount                                       //成交金额
				r.Buyername = b.Buyername                                 //买方名称
				r.Sellername = b.Sellername                               //卖方名称
				r.Rate = b.Rate                                           //折溢价
				r.Blocktradeid = b.Blocktradeid                           //大宗交易ID

				results = append(results, r)
			}
		}

		return results, nil
	default:
		return nil, nil
	}

}
